<?php
class Mem extends CI_Model
{
	public $tbl_name = 'members';
	public $col_memberId = 'memberId';
	public $col_memberName = 'memberName';
	public $col_password = 'password';
	private $col_dateJoin = 'dateJoin';

	public function __contruct()
	{
		parent::__construct();	
	}

	// public function add_status($content, $address, $userID)
	public function add()
	{		
		$data = array(
			'memberName' => $this->input->post('memberName'),
			'password'  => 'matkhau',
			$this->col_dateJoin  => date('Y-m-d H:i:s')
			);

		return $this->db->insert($this->tbl_name, $data);
	}

	public function All(){
		$queryString = 
		"SELECT * FROM members ORDER BY memberId";

		$query = $this->db->query($queryString);
		
		return $query->result();				
	}	

	public function topEarn(){
		$queryString = 
		"SELECT user.username, SUM(leads.point) AS points, members.memberName, members.memberId
		FROM
			user JOIN leads ON user.username = leads.username
		    JOIN members ON members.memberId = user.ref
		GROUP BY members.memberId
		ORDER BY points DESC";

		$query = $this->db->query($queryString);
		
		return $query->result();				
	}
}
?>